package com.yixun.qfbao.model.enums;

import com.yixun.common.utils.EnumUtil;
import com.yixun.qfbao.xf.model.enums.CommissionWayEnum;
import org.apache.commons.lang.StringUtils;

/**
 * 分销佣金状态
 */
public enum CommisionStateEnum {

	/**
	 * 无效
	 */
	COMMISION_STATE_1("0", "无效",null),
	/**
	 * 有效
	 */
	COMMISION_STATE_2("1", "有效",null);


	private final String no;
	private final String des;
	private final Enum parent;

	static{
		EnumUtil.ENUMS_TO_VIEW.put("commission_way", CommissionWayEnum.values());
	}

	/**
	 * 私有构造函数
	 * @param code
	 * @param description
	 */
	CommisionStateEnum(String no, String des, Enum parent) {
		this.no = no;
		this.des = des;
		this.parent = parent;
	}

	/**
	 * @return Returns the no.
	 */
	public String getNo() {
		return no;
	}

	/**
	 * @return Returns the des.
	 */
	public String getDes() {
		return des;
	}

	/**
	 * @return Returns the parent.
	 */
	public Enum getParent() {
		return parent;
	}

	/**
	 * 通过枚举<code>des</code>获得枚举
	 *
	 * @param des
	 * @return
	 */
	public static CommisionStateEnum getByDescription(String des) {
		if(StringUtils.isBlank(des)){
			return null;
		}
		for (CommisionStateEnum menum : values()) {
			if (menum.getDes().equals(des)) {
				return menum;
			}
		}
		return null;
	}
	public static CommisionStateEnum getByNo(String no) {
		if(StringUtils.isBlank(no)){
			return null;
		}
		for (CommisionStateEnum menum : values()) {
			if (menum.getNo().equals(no)) {
				return menum;
			}
		}
		return null;
	}
}
